package com.ssh.bean.factory;

import com.ssh.entity.Entity;
import com.ssh.service.BookService;

public class BeanFactory {
	
	private Object bean;
	
	public BookService getBookService() {
		BookService service = BookService.newInstance();
		return service;
	}
	
	public Entity getBean(Class<? extends Entity> instanceClass) {
		ClassLoader clssLoader = BeanFactory.class.getClassLoader();
		try {
			Class<?> beanClass  = clssLoader.loadClass(instanceClass.getName());
			this.bean = beanClass.newInstance();
			return (Entity) this.bean;
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			return null;
		} catch (InstantiationException e) {
			e.printStackTrace();
			return null;
		} catch (IllegalAccessException e) {
			e.printStackTrace();
			return null;
		}
		
	}
	
}
